package com.voiceblog.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.Cookie;

import org.apache.struts2.ServletActionContext;

import com.voiceblog.model.Album;
import com.voiceblog.model.AlbumDAO;
import com.voiceblog.model.PhotoDAO;
import com.voiceblog.model.Users;

public class AlbumAction extends BaseAction {
	private Integer albumId;
	private Album album;
	private List potolist;
	private PhotoDAO photoDAO;
	private AlbumDAO albumDAO;
	private List<Album> list;
	private Users user;
	private String account;
	private Users blogUser;

	public AlbumDAO getAlbumDAO() {
		return albumDAO;
	}

	public void setAlbumDAO(AlbumDAO albumDAO) {
		this.albumDAO = albumDAO;
	}

	public List getPotolist() {
		return potolist;
	}

	public Album getAlbum() {
		return album;
	}

	public void setAlbum(Album album) {
		this.album = album;
	}

	public PhotoDAO getPhotoDAO() {
		return photoDAO;
	}

	public void setPhotoDAO(PhotoDAO photoDAO) {
		this.photoDAO = photoDAO;
	}

	public void setPotolist(List potolist) {
		this.potolist = potolist;
	}

	public Integer getAlbumId() {
		return albumId;
	}

	public void setAlbumId(Integer albumId) {
		this.albumId = albumId;
	}

	public Users getUser() {
		return user;
	}

	public void setUser(Users user) {
		this.user = user;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public List<Album> getList() {
		return list;
	}

	public void setList(List<Album> list) {
		this.list = list;
	}

	public String list() {
		// System.out.println(voiceBlogDao+" donghua");
		// Users user=voiceBlogDao.getUserByAccount("greg");
		// //(Users)voiceBlogDao.findAllUsers().get(0);
		// //
		// session.put("user", voiceBlogDao.getUserByAccount("greg"));
		// //System.out.println("ceshi");
		//user = getDao().findById(account);
		user=(Users)getSession().get("user");
		list = voiceBlogDao.listMyAlbums(user);
		return SUCCESS;
	}

	public String listPhoto() {
		potolist = photoDAO.findByAlbum(albumId);
		return SUCCESS;
	}

	public String addAlbum() {
		album.setBuildDate(new Date());
		blogUser=(Users) getSession().get("blogUser");

		if (blogUser != null) {
			album.setUsers(blogUser);
			albumDAO.save(album);
			list = voiceBlogDao.listMyAlbums(((Users) session.get("user")));
		} else {
			return INPUT;
		}
		return SUCCESS;
	}

	public Users getBlogUser() {
		return blogUser;
	}

	public void setBlogUser(Users blogUser) {
		this.blogUser = blogUser;
	}
}
